﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Procedure = DeltaFlex.Data.ConsProcedures.Concepte_OT;

namespace DeltaFlex.Data
{
    public class Concepte_OT
    {
        public Concepte_OT()
        { }

        #region Inserts
        public static int InsertarConcepte_OT(int idOrdre, int quantitat, int idArticle, decimal ample,decimal alt, decimal import)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = Procedure.SP_INSERTAR_CONCEPTE_OT;
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_IDORDRE, idOrdre);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_QUANTITAT, quantitat);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_ARTICLE, idArticle);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_AMPLE, ample);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_ALT, alt);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_IMPORT, import);

            return Operacions_BD.Insertar(cmd);
        }
        #endregion

        #region Selects
        public static IDataReader LlistarConceptes_OTByIdOrdre(int idOrdre)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = Procedure.SP_CERCAR_CONCEPTE_OT_BY_IDORDRE;
            
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_IDORDRE, idOrdre);

            return Operacions_BD.Reader(cmd);
        }

        #endregion

        #region Update
        public static void ActualitzarConcepte_OT(int idConcepte, int quantitat, int idArticle, decimal ample, decimal alt, decimal import)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType= CommandType.StoredProcedure;
            cmd.CommandText = Procedure.SP_ACTUALITZARCONCEPTE_OT;

            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_IDCONCEPTE, idConcepte);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_QUANTITAT, quantitat);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_ARTICLE, idArticle);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_AMPLE, ample);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_ALT, alt);
            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_IMPORT, import);

            Operacions_BD.Update(cmd);
        }
        #endregion
    }
}
    

